package edu.school.utils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class WebUtils {
	public static String getRealPath() {
		return "D:\\Code\\lostandfound\\src\\main\\webapp\\upload\\";
	}


	//获取时间
	public static String getDateFormat() {//把String类型的id转化Integer类型的
		Date nowtime=new Date();	
		String createTime="";
		try {
			SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			 createTime=simpleDateFormat.format(nowtime);			
		}catch(Exception e) {};
	        return createTime;
	}
	
	public static  String getOderNo() {//生成订单号
		  SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
	      String newDate=sdf.format(new Date());
	      String result="";
	      Random random=new Random();
	      for(int i=0;i<3;i++){
	          result+=random.nextInt(10);
	      }
	      return newDate+result;
	    
	}
	/*private static void readfile(File[] files) {
		if (files == null) { //如果目录为空, 直接退出
			return;
		}
		for (File f : files) {
        *//*if (f.list().length > 0) {
            System.out.println("目录不为空!");
            f.list();
        }*//*
			if (f.list().length <= 0) {
				System.out.println(f.getName());
				f.delete();
				System.out.println("目录为空!");
			}
		}
	}*/

	public static void deleteImg(String filename) {
		File file
				= new File(getRealPath() + filename);
		System.out.println(getRealPath() + filename);
		if (file.delete()) {
			System.out.println("删除文件成功");
//			File file2 = new File(getRealPath());
//			//获取目录下子文件及子文件夹
//			File[] files = file2.listFiles();
//			readfile(files);
		} else {
			System.out.println("删除文件失败");
		}
	}
}
